package handler

import (
	"github.com/gin-gonic/gin"
	"me/123/api/client"
	"me/123/api/enit/request"
	"me/123/api/enit/response"
	"me/123/common/proto/product"
)

func ProductList(c *gin.Context) {
	var req request.ProductList

	if err := c.ShouldBind(&req); err != nil {
		response.ErrorResponse(c, "参数错误", err.Error())
		return
	}

	list, err := client.ProductList(c, &product.ProductListRequest{
		PriceMin:    req.PriceMin,
		PriceMax:    req.PriceMax,
		IsHot:       req.IsHot,
		IsNew:       req.IsNew,
		TopCategory: req.TopCategory,
		Pages:       req.Pages,
		PagePerNums: req.PagePerNums,
		Keyword:     req.Keyword,
	})
	if err != nil {
		response.ErrorResponse(c, "展示错误", err.Error())
		return
	}

	response.SuccessResponse(c, "ok", list)
}

func List(c *gin.Context) {
	var req request.List

	if err := c.ShouldBind(&req); err != nil {
		response.ErrorResponse(c, "参数错误", err.Error())
		return
	}

	list, err := client.List(c, &product.ListRequest{
		IsHot:     req.IsHot,
		IsPostage: req.IsPostage,
		IsBest:    req.IsBest,
	})
	if err != nil {
		response.ErrorResponse(c, "展示错误", err.Error())
		return
	}

	response.SuccessResponse(c, "ok", list)
}

func UserList(c *gin.Context) {
	userId := c.GetUint("userId")
	list, err := client.UserList(c, &product.UserListRequest{
		UserId: int64(userId),
	})
	if err != nil {
		response.ErrorResponse(c, "展示错误", err.Error())
		return
	}

	response.SuccessResponse(c, "ok", list)
}
